package com.noshufou.android.su.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.util.Log;
import com.noshufou.android.su.HomeActivity;
import com.noshufou.android.su.UpdaterActivity;
import com.noshufou.android.su.preferences.PreferencesActivity;
import com.noshufou.android.su.service.PermissionsDbService;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class Util
{
  public static final int MALICIOUS_NOT = 0;
  public static final int MALICIOUS_PROVIDER_WRITE = 3;
  public static final int MALICIOUS_RESPOND = 2;
  public static final int MALICIOUS_UID = 1;
  private static final String TAG = "Su.Util";
  private static final HashMap<Integer, String> sSystemUids = new HashMap();

  static
  {
    sSystemUids.put(Integer.valueOf(0), "root");
    sSystemUids.put(Integer.valueOf(1000), "system");
    sSystemUids.put(Integer.valueOf(1001), "radio");
    sSystemUids.put(Integer.valueOf(1002), "bluetooth");
    sSystemUids.put(Integer.valueOf(1003), "graphics");
    sSystemUids.put(Integer.valueOf(1004), "input");
    sSystemUids.put(Integer.valueOf(1005), "audio");
    sSystemUids.put(Integer.valueOf(1006), "camera");
    sSystemUids.put(Integer.valueOf(1007), "log");
    sSystemUids.put(Integer.valueOf(1008), "compass");
    sSystemUids.put(Integer.valueOf(1009), "mount");
    sSystemUids.put(Integer.valueOf(1010), "wifi");
    sSystemUids.put(Integer.valueOf(1011), "adb");
    sSystemUids.put(Integer.valueOf(1012), "install");
    sSystemUids.put(Integer.valueOf(1013), "media");
    sSystemUids.put(Integer.valueOf(1014), "dhcp");
    sSystemUids.put(Integer.valueOf(1015), "sdcard_rw");
    sSystemUids.put(Integer.valueOf(1016), "vpn");
    sSystemUids.put(Integer.valueOf(1017), "keystore");
    sSystemUids.put(Integer.valueOf(1018), "usb");
    sSystemUids.put(Integer.valueOf(1021), "gps");
    sSystemUids.put(Integer.valueOf(1025), "nfc");
    sSystemUids.put(Integer.valueOf(2000), "shell");
    sSystemUids.put(Integer.valueOf(2001), "cache");
    sSystemUids.put(Integer.valueOf(2002), "diag");
    sSystemUids.put(Integer.valueOf(3001), "net_bt_admin");
    sSystemUids.put(Integer.valueOf(3002), "net_bt");
    sSystemUids.put(Integer.valueOf(3003), "inet");
    sSystemUids.put(Integer.valueOf(3004), "net_raw");
    sSystemUids.put(Integer.valueOf(3005), "net_admin");
    sSystemUids.put(Integer.valueOf(9998), "misc");
    sSystemUids.put(Integer.valueOf(9999), "nobody");
  }

  public static boolean checkPin(Context paramContext, String paramString)
  {
    String str = PreferenceManager.getDefaultSharedPreferences(paramContext).getString("pin", "");
    return getHash(paramString).equals(str);
  }

  public static boolean elitePresent(Context paramContext, boolean paramBoolean, int paramInt)
  {
    int i = 0;
    PackageManager localPackageManager = paramContext.getPackageManager();
    if (localPackageManager.checkSignatures("com.noshufou.android.su", "com.noshufou.android.su.elite") != 0);
    while (true)
    {
      return i;
      if (paramBoolean)
      {
        try
        {
          int j = localPackageManager.getPackageInfo("com.noshufou.android.su.elite", 0).versionCode;
          if (j < paramInt)
            continue;
          i = 1;
        }
        catch (PackageManager.NameNotFoundException localNameNotFoundException)
        {
        }
        continue;
      }
      i = 1;
    }
  }

  public static List<String> findMaliciousPackages(Context paramContext)
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = paramContext.getPackageManager().getInstalledPackages(4096).iterator();
    while (true)
    {
      if (!localIterator.hasNext())
        return localArrayList;
      PackageInfo localPackageInfo = (PackageInfo)localIterator.next();
      int i = isPackageMalicious(paramContext, localPackageInfo);
      if (i == 0)
        continue;
      localArrayList.add(localPackageInfo.packageName + ":" + i);
    }
  }

  public static String formatDate(Context paramContext, long paramLong)
  {
    String str1 = PreferenceManager.getDefaultSharedPreferences(paramContext).getString("pref_date_format", "default");
    if (str1.equals("default"));
    for (String str2 = android.text.format.DateFormat.getDateFormat(paramContext).format(Long.valueOf(paramLong)); ; str2 = (String)android.text.format.DateFormat.format(str1, paramLong))
      return str2;
  }

  public static String formatDateTime(Context paramContext, long paramLong)
  {
    return formatDate(paramContext, paramLong) + " " + formatTime(paramContext, paramLong);
  }

  public static String formatTime(Context paramContext, long paramLong)
  {
    SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
    boolean bool1 = localSharedPreferences.getBoolean("pref_24_hour_format", true);
    boolean bool2 = localSharedPreferences.getBoolean("pref_show_seconds", false);
    String str1 = "";
    String str2;
    if (bool1)
    {
      str2 = "kk";
      if (!bool2)
        break label112;
    }
    label112: for (String str3 = ":ss"; ; str3 = "")
    {
      Object[] arrayOfObject = new Object[4];
      arrayOfObject[0] = str2;
      arrayOfObject[1] = "mm";
      arrayOfObject[2] = str3;
      arrayOfObject[3] = str1;
      return (String)android.text.format.DateFormat.format(String.format("%s:%s%s%s", arrayOfObject), paramLong);
      str2 = "hh";
      str1 = "aa";
      break;
    }
  }

  public static Drawable getAppIcon(Context paramContext, int paramInt)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    Object localObject = paramContext.getResources().getDrawable(2130837557);
    String[] arrayOfString = localPackageManager.getPackagesForUid(paramInt);
    if (arrayOfString != null);
    while (true)
    {
      try
      {
        Drawable localDrawable = localPackageManager.getApplicationIcon(localPackageManager.getApplicationInfo(arrayOfString[0], 0));
        localObject = localDrawable;
        return localObject;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        Log.e("Su.Util", "No package found matching with the uid " + paramInt);
        continue;
      }
      Log.e("Su.Util", "Package not found for uid " + paramInt);
    }
  }

  public static String getAppName(Context paramContext, int paramInt, boolean paramBoolean)
  {
    Object localObject2;
    if (sSystemUids.containsKey(Integer.valueOf(paramInt)))
    {
      localObject2 = (String)sSystemUids.get(Integer.valueOf(paramInt));
      return localObject2;
    }
    PackageManager localPackageManager = paramContext.getPackageManager();
    Object localObject1 = "Unknown";
    String[] arrayOfString = localPackageManager.getPackagesForUid(paramInt);
    if (arrayOfString != null);
    while (true)
    {
      try
      {
        if (arrayOfString.length != 1)
          continue;
        String str2 = localPackageManager.getApplicationLabel(localPackageManager.getApplicationInfo(arrayOfString[0], 0)).toString();
        localObject1 = str2;
        if (!paramBoolean)
          continue;
        localObject1 = localObject1 + " (" + paramInt + ")";
        localObject2 = localObject1;
        break;
        if (arrayOfString.length <= 1)
          continue;
        localObject1 = "";
        int i = 0;
        if (i >= arrayOfString.length)
          continue;
        localObject1 = localObject1 + arrayOfString[i];
        if (i >= -1 + arrayOfString.length)
          continue;
        String str1 = localObject1 + ", ";
        localObject1 = str1;
        i++;
        continue;
        continue;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        Log.e("Su.Util", "Package name not found", localNameNotFoundException);
        continue;
      }
      Log.e("Su.Util", "Package not found for uid " + paramInt);
    }
  }

  public static String getAppPackage(Context paramContext, int paramInt)
  {
    Object localObject;
    if (sSystemUids.containsKey(Integer.valueOf(paramInt)))
    {
      localObject = (String)sSystemUids.get(Integer.valueOf(paramInt));
      return localObject;
    }
    String[] arrayOfString = paramContext.getPackageManager().getPackagesForUid(paramInt);
    String str = "unknown";
    if (arrayOfString != null)
      if (arrayOfString.length == 1)
        str = arrayOfString[0];
    while (true)
    {
      localObject = str;
      break;
      if (arrayOfString.length <= 1)
        continue;
      str = "";
      for (int i = 0; i < arrayOfString.length; i++)
      {
        str = str + arrayOfString[i];
        if (i >= -1 + arrayOfString.length)
          continue;
        str = str + ", ";
      }
      continue;
      Log.e("Su.Util", "Package not found");
    }
  }

  public static String getHash(String paramString)
  {
    try
    {
      localMessageDigest = MessageDigest.getInstance("SHA-1");
      localMessageDigest.reset();
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      try
      {
        MessageDigest localMessageDigest;
        String str = Base64.encode(localMessageDigest.digest(paramString.getBytes("UTF-8")));
        paramString = str;
        while (true)
        {
          return paramString;
          localNoSuchAlgorithmException = localNoSuchAlgorithmException;
          Log.e("Utils", "NoSuchAlgorithm, storing in plain text...", localNoSuchAlgorithmException);
        }
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        while (true)
          Log.e("Utils", "UnsupportedEncoding, storing in plain text...", localUnsupportedEncodingException);
      }
    }
  }

  public static Drawable getStatusIconDrawable(Context paramContext, int paramInt)
  {
    int[][] arrayOfInt = new int[2][];
    int[] arrayOfInt1 = new int[2];
    arrayOfInt1[0] = 2130837551;
    arrayOfInt1[1] = 2130837549;
    arrayOfInt[0] = arrayOfInt1;
    int[] arrayOfInt2 = new int[2];
    arrayOfInt2[0] = 2130837552;
    arrayOfInt2[1] = 2130837550;
    arrayOfInt[1] = arrayOfInt2;
    String str = PreferenceManager.getDefaultSharedPreferences(paramContext).getString("pref_status_icon_type", "emote");
    int i = 1;
    if (str.equals("dot"))
    {
      i = 0;
      if ((paramInt >= 0) && (paramInt <= 1))
        break label138;
      Log.e("Su.Util", "Bad value given to getStatusButtonDrawable(int). Expecting 0 or 1, got " + paramInt);
    }
    label138: for (Drawable localDrawable = null; ; localDrawable = paramContext.getResources().getDrawable(arrayOfInt[i][paramInt]))
    {
      return localDrawable;
      if (!str.equals("emote"))
        break;
      i = 1;
      break;
    }
  }

  public static String getSuVersion()
  {
    Object localObject1 = null;
    Process localProcess = null;
    while (true)
    {
      int i;
      try
      {
        localProcess = Runtime.getRuntime().exec("sh");
        localDataOutputStream = new DataOutputStream(localProcess.getOutputStream());
        BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(new DataInputStream(localProcess.getInputStream())), 64);
        localDataOutputStream.writeBytes("su -v\n");
        i = 0;
        break label193;
        if (!localBufferedReader.ready())
          continue;
        String str = localBufferedReader.readLine();
        if (str == null)
          continue;
        if (localProcess == null)
          continue;
        localProcess.destroy();
        localObject1 = str;
        return localObject1;
        boolean bool = localBufferedReader.ready();
        if (bool)
          continue;
        try
        {
          Thread.sleep(5L);
          i++;
        }
        catch (InterruptedException localInterruptedException)
        {
          Log.w("Su.Util", "Sleep timer got interrupted...");
          continue;
        }
      }
      catch (IOException localIOException)
      {
        DataOutputStream localDataOutputStream;
        Log.e("Su.Util", "Problems reading current version.", localIOException);
        if (localProcess == null)
          continue;
        localProcess.destroy();
        continue;
        localDataOutputStream.writeBytes("exit\n");
        if (localProcess == null)
          continue;
        localProcess.destroy();
        continue;
      }
      finally
      {
        if (localProcess == null)
          continue;
        localProcess.destroy();
      }
      label193: if (i < 400)
        continue;
    }
  }

  public static int getSuVersionCode()
  {
    int i = 0;
    Process localProcess = null;
    while (true)
    {
      int j;
      try
      {
        localProcess = Runtime.getRuntime().exec("sh");
        localDataOutputStream = new DataOutputStream(localProcess.getOutputStream());
        BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(new DataInputStream(localProcess.getInputStream())), 64);
        localDataOutputStream.writeBytes("su -v\n");
        j = 0;
        break label245;
        if (!localBufferedReader.ready())
          continue;
        String str1 = localBufferedReader.readLine();
        if ((str1 == null) || (Integer.parseInt(str1.substring(0, 1)) <= 2))
          continue;
        localDataOutputStream.writeBytes("su -V\n");
        String str2 = localBufferedReader.readLine();
        if (str2 == null)
          continue;
        int k = Integer.parseInt(str2);
        i = k;
        return i;
        boolean bool = localBufferedReader.ready();
        if (bool)
          continue;
        try
        {
          Thread.sleep(5L);
          j++;
        }
        catch (InterruptedException localInterruptedException)
        {
          Log.w("Su.Util", "Sleep timer got interrupted...");
          continue;
        }
      }
      catch (IOException localIOException)
      {
        DataOutputStream localDataOutputStream;
        Log.e("Su.Util", "Problems reading current version.", localIOException);
        if (localProcess == null)
          continue;
        localProcess.destroy();
        continue;
        if (localProcess == null)
          continue;
        localProcess.destroy();
        continue;
        localDataOutputStream.writeBytes("exit\n");
        if (localProcess == null)
          continue;
        localProcess.destroy();
        continue;
      }
      finally
      {
        if (localProcess == null)
          continue;
        localProcess.destroy();
      }
      label245: if (j < 400)
        continue;
    }
  }

  public static String getUidName(Context paramContext, int paramInt, boolean paramBoolean)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    String str = "";
    if (paramInt == 0)
      str = "root";
    while (true)
    {
      if (paramBoolean)
        str = str + " (" + paramInt + ")";
      return str;
      localPackageManager.getNameForUid(paramInt);
    }
  }

  public static void goHome(Context paramContext)
  {
    Intent localIntent;
    if (PreferenceManager.getDefaultSharedPreferences(paramContext).getBoolean("pref_ghost_mode", false))
      localIntent = new Intent(paramContext, HomeActivity.class);
    while (true)
    {
      localIntent.setFlags(67108864);
      paramContext.startActivity(localIntent);
      return;
      localIntent = new Intent();
      localIntent.setComponent(new ComponentName("com.noshufou.android.su", "com.noshufou.android.su.Su"));
    }
  }

  public static int isPackageMalicious(Context paramContext, PackageInfo paramPackageInfo)
  {
    int i = 0;
    if (paramPackageInfo.packageName.equals(paramContext.getPackageName()));
    do
      while (true)
      {
        return i;
        if (paramPackageInfo.applicationInfo.uid != paramContext.getApplicationInfo().uid)
          break;
        i = 1;
      }
    while (paramPackageInfo.requestedPermissions == null);
    String[] arrayOfString1 = new String[2];
    arrayOfString1[i] = "com.noshufou.android.su.RESPOND";
    arrayOfString1[1] = "com.noshufou.android.su.provider.WRITE";
    String[] arrayOfString2 = paramPackageInfo.requestedPermissions;
    int j = arrayOfString2.length;
    int k = 0;
    label78: String str;
    if (k < j)
      str = arrayOfString2[k];
    for (int m = 0; ; m++)
    {
      if (m >= 2)
      {
        k++;
        break label78;
        break;
      }
      if ((!str.equals(arrayOfString1[m])) || (paramContext.getPackageManager().checkPermission(arrayOfString1[m], paramPackageInfo.packageName) != 0))
        continue;
      i = m + 2;
      break;
    }
  }

  public static boolean isSuCurrent()
  {
    if (getSuVersionCode() < 10);
    for (int i = 0; ; i = 1)
      return i;
  }

  public static void launchPreferences(Context paramContext)
  {
    paramContext.startActivity(new Intent(paramContext, PreferencesActivity.class));
  }

  public static void showOutdatedNotification(Context paramContext)
  {
    if (PreferenceManager.getDefaultSharedPreferences(paramContext).getBoolean("pref_outdated_notification", true))
    {
      NotificationManager localNotificationManager = (NotificationManager)paramContext.getSystemService("notification");
      Notification localNotification = new Notification(2130837556, paramContext.getString(2131427504), System.currentTimeMillis());
      PendingIntent localPendingIntent = PendingIntent.getActivity(paramContext, 0, new Intent(paramContext, UpdaterActivity.class), 0);
      localNotification.setLatestEventInfo(paramContext, paramContext.getString(2131427505), paramContext.getString(2131427506), localPendingIntent);
      localNotification.flags = (0x10 | localNotification.flags);
      localNotificationManager.notify(42, localNotification);
    }
  }

  public static void toggleAppIcon(Context paramContext, boolean paramBoolean)
  {
    ComponentName localComponentName = new ComponentName("com.noshufou.android.su", "com.noshufou.android.su.Su");
    PackageManager localPackageManager = paramContext.getPackageManager();
    if (paramBoolean);
    for (int i = 1; ; i = 2)
    {
      localPackageManager.setComponentEnabledSetting(localComponentName, i, 1);
      return;
    }
  }

  public static void updatePermissionsDb(Context paramContext)
  {
    PreferenceManager.getDefaultSharedPreferences(paramContext).edit().putBoolean("permissions_dirty", true).commit();
    Log.d("Su.Util", "Start PermissionsDbService");
    paramContext.startService(new Intent(paramContext, PermissionsDbService.class));
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.util.Util
 * JD-Core Version:    0.6.0
 */